public class NextDate {

    private static boolean leapyear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
    }

    private static String date(int month, int day, int year) {
        return Integer.toString(month) + "-" + Integer.toString(day) + "-" + Integer.toString(year);
    }

    public static String getDate(int month, int day, int year) {
        if (!(year >= 1900 && year <= 2050)) {
            return "年份错误";
        }
        if (month > 12 || month < 1) {
            return "月份错误";
        }
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            if (day > 31 || day < 1) {
                return "天数超出范围";
            }
        }
        if (month == 4 || month == 6 || month == 9 || month == 11) {
            if (day > 30 || day < 1) {
                return "天数超出范围";
            }
        }
        if (leapyear(year)) {
            if (month == 2) {
                if (day > 29) {
                    return "天数超出范围";
                } else {
                    if (day == 29) {
                        day = 1;
                    } else day++;
                }
            }
        } else {
            if (month == 2) {
                if (day > 28) {
                    return "天数超出范围";
                } else {
                    if (day == 28) {
                        day = 1;
                    } else day++;
                }
            }
        }
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
                if (day == 31) {
                    int nextMonth = month + 1;
                    int nextDay = 1;
                    return date(nextMonth, nextDay, year);
                } else {
                    int nextDay = day + 1;
                    return date(month, nextDay, year);
                }
            case 2:
                if (day == 1) {
                    int nextMonth = month + 1;
                    return date(nextMonth, day, year);
                } else {
                    return date(month, day, year);
                }
            case 4:
            case 6:
            case 9:
            case 11:
                if (day == 30) {
                    int nextMonth = month + 1;
                    int nextDay = 1;
                    return date(nextMonth, nextDay, year);
                } else {
                    int nextDay = day + 1;
                    return date(month, nextDay, year);
                }
            case 12:
                if (day == 31) {
                    int nextMonth = 1;
                    int nextDay = 1;
                    int nextYear = year + 1;
                    return date(nextMonth, nextDay, nextYear);
                } else {
                    int nextDay = day + 1;
                    return date(month, nextDay, year);
                }
        }
        return null;
    }
}
